import 'package:OASys/views/announcement/announcementPage.dart';
import 'package:OASys/views/event/eventPage.dart';
import 'package:OASys/views/home/Tabs.dart';
import 'package:OASys/views/icon/myIcons.dart';
import 'package:OASys/views/matter/matterPage.dart';
import 'package:OASys/views/meeting/meetingPage.dart';
import 'package:OASys/views/menu/menuPage.dart';
import 'package:OASys/views/paper/paperPage.dart';
import 'package:OASys/views/personnel/personnelPage.dart';
import 'package:OASys/views/project/projectPage.dart';
import 'package:OASys/views/report/reportPage.dart';
import 'package:OASys/views/role/rolePage.dart';
import 'package:OASys/views/schedule/schedulePage.dart';
import 'package:OASys/views/user/pwdPage.dart';
import 'package:OASys/views/user/userPage.dart';
import 'package:flutter/material.dart';

class MenuDrawer extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(color: Color.fromRGBO(245, 245, 245, 1)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // UserAccountsDrawerHeader(
          //   accountName: Text('Mr.Hu'),
          //   accountEmail: Text('tsanfong@163.com'),
          //   currentAccountPicture: CircleAvatar(
          //     backgroundImage:
          //         NetworkImage('http://tsanfong.top/testAvatar.jpg'),
          //   ),
          // ),
          InfoContainer(),
          MenuDrawerItem(Icons.home, "主页", Tabs(), '/home'),
          MenuDrawerItem(Icons.supervisor_account, "用户管理", UserPage(), '/user'),
          MenuDrawerItem(
              Icons.account_circle_rounded, "角色管理", Rolepage(), '/role'),
          MenuDrawerItem(Icons.vpn_key_outlined, "权限管理", MenuPage(), '/menu'),
          MenuDrawerItem(MyIcons.meeting, "会议管理", MeetingPage(), '/meeting'),
          MenuDrawerItem(Icons.polymer, "流程管理", EventPage(), '/event'),
          MenuDrawerItem(
              Icons.assignment, "通知公告", AnnouncementPage(), '/announcement'),
          MenuDrawerItem(Icons.date_range, "日程管理", SchedulePage(), '/schedule'),
          MenuDrawerItem(
              Icons.chrome_reader_mode, "工作汇报", ReportPage(), '/report'),
          MenuDrawerItem(
              Icons.file_copy_outlined, "文件中心", PaperPage(), '/paper'),
          MenuDrawerItem(Icons.group_work, "工作事项", MatterPage(), '/matter'),
          MenuDrawerItem(Icons.layers_sharp, "项目管理", ProjectPage(), '/project'),
          MenuDrawerItem(
              Icons.line_style, "人事管理", PersonnelPage(), '/personnel'),
          MenuDrawerItem(Icons.lock, "修改密码", PwdPage(), '/pwd'),
        ],
      ),
    );
  }
}

class InfoContainer extends StatelessWidget {
  const InfoContainer({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(5, 50, 5, 20),
      child: Card(
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              alignment: Alignment.topLeft,
              padding: EdgeInsets.fromLTRB(50, 50, 50, 10),
              margin: EdgeInsets.all(20),
              width: 70,
              height: 70,
              decoration: BoxDecoration(
                image: DecorationImage(
                  image: NetworkImage('http://tsanfong.top/testAvatar.jpg'),
                  fit: BoxFit.cover,
                ),
                border: Border.all(
                  color: Colors.blue,
                  width: 2,
                ),
                shape: BoxShape.circle,
              ),
            ),
            Container(
              margin: EdgeInsets.all(15),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '姓名：  Mr.Hu',
                    style: TextStyle(fontSize: 10),
                  ),
                  Text(
                    '性别：  男',
                    style: TextStyle(fontSize: 10),
                  ),
                  Text(
                    '职位：  Java工程师',
                    style: TextStyle(fontSize: 10),
                  ),
                  Text(
                    '部门：  研发部',
                    style: TextStyle(fontSize: 10),
                  ),
                  Text(
                    '团队：  WTeam',
                    style: TextStyle(fontSize: 10),
                  ),
                  Text(
                    '小组：  百量养猪厂',
                    style: TextStyle(fontSize: 10),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class MenuDrawerItem extends StatelessWidget {
  final String itemName;

  final Widget toPage;

  final IconData iconData;

  final String routeName;

  MenuDrawerItem(this.iconData, this.itemName, this.toPage, this.routeName);

  @override
  Widget build(BuildContext context) {
    return Card(
      child: Container(
        height: 30,
        child: FlatButton(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                child: Row(
                  children: [
                    SizedBox(
                      width: 10,
                      height: 20,
                    ),
                    Icon(
                      this.iconData,
                      color: Colors.blue,
                      size: 20,
                    ),
                    SizedBox(
                      width: 10,
                    ),
                    Text(
                      "${this.itemName}",
                      style: TextStyle(color: Colors.blue, fontSize: 10),
                    ),
                  ],
                ),
              ),
              Icon(
                Icons.keyboard_arrow_right_outlined,
                color: Colors.blue,
              ),
            ],
          ),
          onPressed: () {
            Navigator.of(context).pop();
            // 如果是跳转主页只需隐藏菜单，不需要跳转
            Navigator.of(context).pushNamed(routeName);
          },
          color: Colors.white,
          shape: Border(
            bottom: BorderSide(
              color: Colors.blue,
            ),
          ),
        ),
      ),
    );
  }
}
